﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using IHISCETeim.Library;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using IHISCETeim.Model;

namespace IHISCETeim.DAL
{
    public class JSDWFFlowConfigDAL
    {
        public static int Add(JSDWFFlowConfigInfo obj)
        {
            Database DB = DatabaseFactory.CreateDatabase();

            DbCommand dbCommand = DB.GetStoredProcCommand("JSDWFFlowConfig_Add", obj.FlowID, obj.State, obj.UserName, obj.Remark, obj.AdtlvlID);
            return Convert.ToInt32(DB.ExecuteScalar(dbCommand));
        }

        public static bool Delete(int FlowID, int AdtlvlID)
        {
            Database DB = DatabaseFactory.CreateDatabase();

            DbCommand dbCommand = DB.GetStoredProcCommand("JSDWFFlowConfig_Delete", FlowID, AdtlvlID);
            try
            {
                DB.ExecuteScalar(dbCommand);
                return true;
            }
            catch
            {
                return false;
            }
        }
        public static IDataReader GetAll(int AdtlvlID)
	    {
		    Database DB = DatabaseFactory.CreateDatabase();

            DbCommand dbCommand = DB.GetStoredProcCommand("JSDWFFlowConfig_GetAll", AdtlvlID);
            return DB.ExecuteReader(dbCommand);
	    }

        public static DataTable GetAllToDataTable(int AdtlvlID)
        {
            Database DB = DatabaseFactory.CreateDatabase();

            DbCommand dbCommand = DB.GetStoredProcCommand("JSDWFFlowConfig_GetAll", AdtlvlID);
            return DB.ExecuteDataSet(dbCommand).Tables[0];
        }

        public static IDataReader GetByID(int FlowID, int AdtlvlID)
        {
            Database DB = DatabaseFactory.CreateDatabase();

            DbCommand dbCommand = DB.GetStoredProcCommand("JSDWFFlowConfig_GetByID", FlowID, AdtlvlID);
            return DB.ExecuteReader(dbCommand);
        }

        public static bool Update(JSDWFFlowConfigInfo obj)
        {
            Database DB = DatabaseFactory.CreateDatabase();

            DbCommand dbCommand = DB.GetStoredProcCommand("JSDWFFlowConfig_Update", obj.FlowID, obj.State, obj.UserName, obj.Remark, obj.AdtlvlID);
            try
            {
                DB.ExecuteScalar(dbCommand);
                return true;
            }
            catch (Exception exc)
            {
                return false;
            }
        }
    }
}
